<?php

namespace App\Admin\Controllers;

use App\Models\ExcelTemplate;
use App\Models\WpsFormList;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class WpsFormListController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'WPS表单记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new WpsFormList());

        $grid->column('id', __('ID'));
        $grid->column('title', __('表单名称(点击进入)'))->display(function ($title, $column) {
            return $column->link('/admin/form/answer?wps_form_id=' . $this->id, '_self');
        });
        $grid->column('remark', __('备注'));
        $grid->column('excel_template_id', __('模版名称'))->display(function ($id) {
            return ExcelTemplate::query()->where('id', $id)->value('title') ?: '';
        });
        $grid->column('create_time', __('创建时间'));
        $grid->column('update_time', __('更新时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(WpsFormList::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', __('表单名称'));
        $show->field('remark', __('备注'));
        $show->field('excel_template_id', __('模版ID'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new WpsFormList());

        $form->text('title', __('表单名称'));
        $form->text('remark', __('备注'));
        $form->number('excel_template_id', __('模版ID'));
        $form->footer(function ($footer) {

            // 去掉`重置`按钮
            $footer->disableReset();

            // 去掉`提交`按钮
//            $footer->disableSubmit();

            // 去掉`查看`checkbox
            $footer->disableViewCheck();

            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
